summaryrefslogtreecommitdiffstats
path: root/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/SettingsViewModel.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/app/src/main/java/org/yuzu/yuzu_emu/model/SettingsViewModel.kt')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/model/SettingsViewModel.kt57
1 files changed, 23 insertions, 34 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/SettingsViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/SettingsViewModel.kt
index d16d15fa6..53fa7a8de 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/SettingsViewModel.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/SettingsViewModel.kt
@@ -3,48 +3,43 @@
package org.yuzu.yuzu_emu.model
-import androidx.lifecycle.LiveData
-import androidx.lifecycle.MutableLiveData
-import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
import org.yuzu.yuzu_emu.R
import org.yuzu.yuzu_emu.YuzuApplication
import org.yuzu.yuzu_emu.features.settings.model.view.SettingsItem
-class SettingsViewModel(private val savedStateHandle: SavedStateHandle) : ViewModel() {
+class SettingsViewModel : ViewModel() {
var game: Game? = null
var shouldSave = false
var clickedItem: SettingsItem? = null
- private val _toolbarTitle = MutableLiveData("")
- val toolbarTitle: LiveData<String> get() = _toolbarTitle
+ val shouldRecreate: StateFlow<Boolean> get() = _shouldRecreate
+ private val _shouldRecreate = MutableStateFlow(false)
- private val _shouldRecreate = MutableLiveData(false)
- val shouldRecreate: LiveData<Boolean> get() = _shouldRecreate
+ val shouldNavigateBack: StateFlow<Boolean> get() = _shouldNavigateBack
+ private val _shouldNavigateBack = MutableStateFlow(false)
- private val _shouldNavigateBack = MutableLiveData(false)
- val shouldNavigateBack: LiveData<Boolean> get() = _shouldNavigateBack
+ val shouldShowResetSettingsDialog: StateFlow<Boolean> get() = _shouldShowResetSettingsDialog
+ private val _shouldShowResetSettingsDialog = MutableStateFlow(false)
- private val _shouldShowResetSettingsDialog = MutableLiveData(false)
- val shouldShowResetSettingsDialog: LiveData<Boolean> get() = _shouldShowResetSettingsDialog
+ val shouldReloadSettingsList: StateFlow<Boolean> get() = _shouldReloadSettingsList
+ private val _shouldReloadSettingsList = MutableStateFlow(false)
- private val _shouldReloadSettingsList = MutableLiveData(false)
- val shouldReloadSettingsList: LiveData<Boolean> get() = _shouldReloadSettingsList
+ val isUsingSearch: StateFlow<Boolean> get() = _isUsingSearch
+ private val _isUsingSearch = MutableStateFlow(false)
- private val _isUsingSearch = MutableLiveData(false)
- val isUsingSearch: LiveData<Boolean> get() = _isUsingSearch
+ val sliderProgress: StateFlow<Int> get() = _sliderProgress
+ private val _sliderProgress = MutableStateFlow(-1)
- val sliderProgress = savedStateHandle.getStateFlow(KEY_SLIDER_PROGRESS, -1)
+ val sliderTextValue: StateFlow<String> get() = _sliderTextValue
+ private val _sliderTextValue = MutableStateFlow("")
- val sliderTextValue = savedStateHandle.getStateFlow(KEY_SLIDER_TEXT_VALUE, "")
-
- val adapterItemChanged = savedStateHandle.getStateFlow(KEY_ADAPTER_ITEM_CHANGED, -1)
-
- fun setToolbarTitle(value: String) {
- _toolbarTitle.value = value
- }
+ val adapterItemChanged: StateFlow<Int> get() = _adapterItemChanged
+ private val _adapterItemChanged = MutableStateFlow(-1)
fun setShouldRecreate(value: Boolean) {
_shouldRecreate.value = value
@@ -67,8 +62,8 @@ class SettingsViewModel(private val savedStateHandle: SavedStateHandle) : ViewMo
}
fun setSliderTextValue(value: Float, units: String) {
- savedStateHandle[KEY_SLIDER_PROGRESS] = value
- savedStateHandle[KEY_SLIDER_TEXT_VALUE] = String.format(
+ _sliderProgress.value = value.toInt()
+ _sliderTextValue.value = String.format(
YuzuApplication.appContext.getString(R.string.value_with_units),
value.toInt().toString(),
units
@@ -76,21 +71,15 @@ class SettingsViewModel(private val savedStateHandle: SavedStateHandle) : ViewMo
}
fun setSliderProgress(value: Float) {
- savedStateHandle[KEY_SLIDER_PROGRESS] = value
+ _sliderProgress.value = value.toInt()
}
fun setAdapterItemChanged(value: Int) {
- savedStateHandle[KEY_ADAPTER_ITEM_CHANGED] = value
+ _adapterItemChanged.value = value
}
fun clear() {
game = null
shouldSave = false
}
-
- companion object {
- const val KEY_SLIDER_TEXT_VALUE = "SliderTextValue"
- const val KEY_SLIDER_PROGRESS = "SliderProgress"
- const val KEY_ADAPTER_ITEM_CHANGED = "AdapterItemChanged"
- }
}